<template>
    <div class="blank"></div>
    <div class="detail-user" v-if="pForm.show">
        <div
            style="flex-grow: 1;border-left: 1px solid var(--van-border-color);border-right: 1px solid var(--van-border-color)">
            <bDetail :instance="pForm" title="基本信息">
                <template #edit><span class="textbutton" style="margin-right:1em" @click="pForm.show = false"
                        v-if="but.has('updataUser')">{{ but.get('updataUser') }}</span></template>
            </bDetail>
        </div>
        <div class="blank"></div>
    </div>
    <bForm v-else :instance="pForm">
        <template #top>
            <div style="text-align: right;"><a class="textbutton" href="https://lbs.amap.com/tools/picker"
                    target="_blank">坐标拾取</a>
            </div>
        </template>
        <div style="display: grid;grid-gap: 2vw;grid-template-columns: 1fr 3fr;margin: 12px 2vw;">
            <!-- 若存在后端，取消时重新拉取数据 -->
            <Button @click="() => { pForm.setData(); pForm.show = true }" style="border-radius: 6px;" type="danger">
                取消
            </Button>
            <Button @click="onConfrim" style="border-radius: 6px;" type="primary">完成
            </Button>
        </div>
    </bForm>

    <bCropper v-model:img="tempImg"></bCropper>
</template>
<script lang="ts" setup>
import { useRoute } from 'vue-router';
import bDetail from "@m/components/public/b_detail.vue";
import bForm from "@m/components/public/b_form.vue";
import bCropper from "@m/components/public/b_cropper.vue";
import { Button } from "vant";
import { pagebuttonStore } from '@b/store';
import { ref, watch } from 'vue';
import { UserForm } from '@b/index/user';
const route = useRoute()
const tempImg = ref('')
const pForm = new UserForm()
pForm.show = true
const id = route.query.id
pForm.id = Number(id)
const but = pagebuttonStore().button;

(async () => {
    await pForm.setData()
    pForm.init()
})()

pForm.showCroppe = (url: string) => {
    tempImg.value = url
}
watch(tempImg, (url) => {
    pForm.data.headImg = url
})
const onConfrim = async () => {
    await pForm.updateData();
    await pForm.setData();
    pForm.show = true
}

</script>

<style scoped>
.detail-user {
    display: flex;
    align-items: center;
    background: var(--van-background);
    padding: 6px 0;
}
</style>